Skip to content

Properties need to be allowed by Symfony's serializer at the same time#4031

Closed
kayue wants to merge 4 commits into
api-platform:mainfrom
kayue:patch-4
Closed

Properties need to be allowed by Symfony's serializer at the same time#4031
kayue wants to merge 4 commits into
api-platform:mainfrom
kayue:patch-4

Conversation

@kayue

@kayue kayue commented Feb 6, 2021

Copy link
Copy Markdown
Q A
Bug fix? no
New feature? no
BC breaks? yes
Deprecations? no
Tickets
License MIT
Doc PR api-platform/docs#...

The Problem

  • Properties defined in Api Platform's resource cannot be hide by Symfony's serialization group
  • Properties's visibility can be defined in both api resource and serializer config. This lead to confusion and unexpected behaviour.

The Solution

  • Call parent::getAllowedAttributes() in ApiPlatform\Core\Serializer\AbstractItemNormalizer.
  • But this will change the behaviour of ApiPlatform completely, this will force developer to well define their property in Serializer. Not sure is it something you want to merge easily.

@alanpoulain

Copy link
Copy Markdown
Member

Hello,
This is a BC, so it should be made configurable and target main.
Do you have a use case that shows the issue? Maybe the @Ignore annotation?
In this case it would be great to have a Behat scenario showing the issue.

@kayue
kayue changed the base branch from 2.5 to main February 15, 2021 15:41
@kayue
kayue force-pushed the patch-4 branch 2 times, most recently from 92f9aa9 to 02d701d Compare February 15, 2021 16:51
@kayue

kayue commented Feb 15, 2021

Copy link
Copy Markdown
Author

@alanpoulain Updated the branch and added a unit test.

In Sylius it uses both FosRestBundle and ApiPlatform, and they basically shared the same serializer. Therefore I want to be able to control property visibility using serialization group so the settings can be shared by both bundles. In fact this is what ApiPlatform recommended to use as well.

ApiPlatform's AbstractItemNormalizer::getAllowedAttributes() is extended from \Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer, but it doesn't call parent, therefore the behaviour is different from Symfony and it is unexpected.

@stale

stale Bot commented Nov 4, 2022

Copy link
Copy Markdown

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale Bot added the wontfix label Nov 4, 2022
@stale

stale Bot commented Jan 3, 2023

Copy link
Copy Markdown

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale Bot added the stale label Jan 3, 2023
@stale stale Bot closed this Jan 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants